﻿using JMcms.Common;
using JMcms.DBUtility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace JMcms.Web.Plugin.Job.DAL
{
   public class job_apply
    {
        private string databaseprefix;
        public job_apply(string _databaseprefix)
        {
            this.databaseprefix = _databaseprefix;
        }
        public bool Exists(int id)
        {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("select count(1) from " + this.databaseprefix + "job_apply");
            stringBuilder.Append(" where id=@id");
            SqlParameter[] array = new SqlParameter[]
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            array[0].Value = id;
            return DbHelperSQL.Exists(stringBuilder.ToString(), array);
        }
        public int Add(JMcms.Web.Plugin.Job.Model.job_apply model)
        {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("insert into " + this.databaseprefix + "job_apply(");
            stringBuilder.Append("job_id,title,sex,age,education,tel,email,address,add_time)");
            stringBuilder.Append(" values (");
            stringBuilder.Append("@job_id,@title,@sex,@age,@education,@tel,@email,@address,@add_time)");
            SqlParameter[] array = new SqlParameter[]
            {
                new SqlParameter("@job_id", SqlDbType.Int, 4),
                new SqlParameter("@title", SqlDbType.NVarChar, 100),
                new SqlParameter("@sex", SqlDbType.NVarChar, 10),
                new SqlParameter("@age", SqlDbType.Int, 4),
                new SqlParameter("@education", SqlDbType.NVarChar, 30),
                new SqlParameter("@tel", SqlDbType.NVarChar, 30),
                new SqlParameter("@email", SqlDbType.NVarChar, 30),
                new SqlParameter("@address", SqlDbType.NVarChar, 100),
                new SqlParameter("@add_time", SqlDbType.DateTime)
            };
            array[0].Value = model.job_id;
            array[1].Value = model.title;
            array[2].Value = model.sex;
            array[3].Value = model.age;
            array[4].Value = model.education;
            array[5].Value = model.tel;
            array[6].Value = model.email;
            array[7].Value = model.address;
            array[8].Value = model.add_time;
            return DbHelperSQL.ExecuteSql(stringBuilder.ToString(), array);
        }
        public bool Update(JMcms.Web.Plugin.Job.Model.job_apply model)
        {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("update " + this.databaseprefix + "job_apply set ");
            stringBuilder.Append("job_id=@job_id,");
            stringBuilder.Append("title=@title,");
            stringBuilder.Append("sex=@sex,");
            stringBuilder.Append("age=@age,");
            stringBuilder.Append("education=@education,");
            stringBuilder.Append("tel=@tel,");
            stringBuilder.Append("email=@email,");
            stringBuilder.Append("address=@address,");
            stringBuilder.Append("add_time=@add_time");
            stringBuilder.Append(" where id=@id");
            SqlParameter[] array = new SqlParameter[]
            {
                new SqlParameter("@job_id", SqlDbType.Int, 4),
                new SqlParameter("@title", SqlDbType.NVarChar, 100),
                new SqlParameter("@sex", SqlDbType.NVarChar, 10),
                new SqlParameter("@age", SqlDbType.Int, 4),
                new SqlParameter("@education", SqlDbType.NVarChar, 30),
                new SqlParameter("@tel", SqlDbType.NVarChar, 30),
                new SqlParameter("@email", SqlDbType.NVarChar, 30),
                new SqlParameter("@address", SqlDbType.NVarChar, 100),
                new SqlParameter("@add_time", SqlDbType.DateTime),
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            array[0].Value = model.job_id;
            array[1].Value = model.title;
            array[2].Value = model.sex;
            array[3].Value = model.age;
            array[4].Value = model.education;
            array[5].Value = model.tel;
            array[6].Value = model.email;
            array[7].Value = model.address;
            array[8].Value = model.add_time;
            array[9].Value = model.id;
            int num = DbHelperSQL.ExecuteSql(stringBuilder.ToString(), array);
            return num > 0;
        }
        public bool Delete(int id)
        {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("delete from " + this.databaseprefix + "job_apply ");
            stringBuilder.Append(" where id=@id");
            SqlParameter[] array = new SqlParameter[]
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            array[0].Value = id;
            int num = DbHelperSQL.ExecuteSql(stringBuilder.ToString(), array);
            return num > 0;
        }
        public bool Deletes(int jobId)
        {
            string text = "delete from " + this.databaseprefix + "job_apply where job_id=@job_id ";
            SqlParameter[] array = new SqlParameter[]
            {
                new SqlParameter("@job_id", SqlDbType.Int, 4)
            };
            array[0].Value = jobId;
            int num = DbHelperSQL.ExecuteSql(text, array);
            return num > 0;
        }
        public JMcms.Web.Plugin.Job.Model.job_apply GetModel(int id)
        {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("select id,job_id,title,sex,age,education,tel,email,address,add_time from " + this.databaseprefix + "job_apply ");
            stringBuilder.Append(" where id=@id");
            SqlParameter[] array = new SqlParameter[]
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            array[0].Value = id;
            JMcms.Web.Plugin.Job.Model.job_apply job_apply = new JMcms.Web.Plugin.Job.Model.job_apply();
            DataSet dataSet = DbHelperSQL.Query(stringBuilder.ToString(), array);
            bool flag = dataSet.Tables[0].Rows.Count > 0;
            JMcms.Web.Plugin.Job.Model.job_apply result;
            if (flag)
            {
                result = this.DataRowToModel(dataSet.Tables[0].Rows[0]);
            }
            else
            {
                result = null;
            }
            return result;
        }
        public JMcms.Web.Plugin.Job.Model.job_apply DataRowToModel(DataRow row)
        {
            JMcms.Web.Plugin.Job.Model.job_apply job_apply = new JMcms.Web.Plugin.Job.Model.job_apply();
            bool flag = row != null;
            if (flag)
            {
                bool flag2 = row["id"] != null && row["id"].ToString() != "";
                if (flag2)
                {
                    job_apply.id = int.Parse(row["id"].ToString());
                }
                bool flag3 = row["job_id"] != null && row["job_id"].ToString() != "";
                if (flag3)
                {
                    job_apply.job_id = new int?(int.Parse(row["job_id"].ToString()));
                }
                bool flag4 = row["title"] != null;
                if (flag4)
                {
                    job_apply.title = row["title"].ToString();
                }
                bool flag5 = row["sex"] != null;
                if (flag5)
                {
                    job_apply.sex = row["sex"].ToString();
                }
                bool flag6 = row["age"] != null && row["age"].ToString() != "";
                if (flag6)
                {
                    job_apply.age = new int?(int.Parse(row["age"].ToString()));
                }
                bool flag7 = row["education"] != null;
                if (flag7)
                {
                    job_apply.education = row["education"].ToString();
                }
                bool flag8 = row["tel"] != null;
                if (flag8)
                {
                    job_apply.tel = row["tel"].ToString();
                }
                bool flag9 = row["email"] != null;
                if (flag9)
                {
                    job_apply.email = row["email"].ToString();
                }
                bool flag10 = row["address"] != null;
                if (flag10)
                {
                    job_apply.address = row["address"].ToString();
                }
                bool flag11 = row["add_time"] != null && row["add_time"].ToString() != "";
                if (flag11)
                {
                    job_apply.add_time = DateTime.Parse(row["add_time"].ToString());
                }
            }
            return job_apply;
        }
        public DataSet GetList(string strWhere)
        {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("select id,job_id,title,sex,age,education,tel,email,address,add_time ");
            stringBuilder.Append(" FROM " + this.databaseprefix + "job_apply ");
            bool flag = strWhere.Trim() != "";
            if (flag)
            {
                stringBuilder.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(stringBuilder.ToString());
        }
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("select ");
            bool flag = Top > 0;
            if (flag)
            {
                stringBuilder.Append(" top " + Top.ToString());
            }
            stringBuilder.Append(" id,job_id,title,sex,age,education,tel,email,address,add_time ");
            stringBuilder.Append(" FROM " + this.databaseprefix + "job_apply ");
            bool flag2 = strWhere.Trim() != "";
            if (flag2)
            {
                stringBuilder.Append(" where " + strWhere);
            }
            stringBuilder.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(stringBuilder.ToString());
        }
        public DataSet GetList(int pageSize, int pageIndex, string strWhere, string filedOrder, out int recordCount)
        {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("select * FROM " + this.databaseprefix + "job_apply");
            bool flag = strWhere.Trim() != "";
            if (flag)
            {
                stringBuilder.Append(" where " + strWhere);
            }
            recordCount = Convert.ToInt32(DbHelperSQL.GetSingle(PagingHelper.CreateCountingSql(stringBuilder.ToString())));
            return DbHelperSQL.Query(PagingHelper.CreatePagingSql(recordCount, pageSize, pageIndex, stringBuilder.ToString(), filedOrder));
        }
    }
}
